package com.yearEndWorkload.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yearEndWorkload.common.Result;
import com.yearEndWorkload.mapper.PerformanceAppraisalMapper;
import com.yearEndWorkload.pojo.entity.PerformanceAppraisal;
import com.yearEndWorkload.pojo.excel.importTemplate.PerformanceAppraisalExcel;
import com.yearEndWorkload.pojo.form.add.AddPerformanceAppraisalForm;
import com.yearEndWorkload.pojo.form.update.UpdatePerformanceAppraisalForm;
import com.yearEndWorkload.pojo.query.PerformanceAppraisalQuery;
import com.yearEndWorkload.pojo.vo.BaseVo;
import com.yearEndWorkload.pojo.vo.PerformanceAppraisalVo;
import com.yearEndWorkload.service.PerformanceAppraisalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author admin
* @description 针对表【performance_appraisal(考核平均绩效管理)】的数据库操作Service实现
* @createDate 2024-03-06 22:45:52
*/
@Service
public class PerformanceAppraisalServiceImpl extends ServiceImpl<PerformanceAppraisalMapper, PerformanceAppraisal>
    implements PerformanceAppraisalService{
    @Autowired
    public PerformanceAppraisalMapper performanceAppraisalMapper;
    @Override
    public Result getList(PerformanceAppraisalQuery performanceAppraisalQuery){
        Page<PerformanceAppraisalVo> page =new Page<>(performanceAppraisalQuery.getCurrentPage(),performanceAppraisalQuery.getPageSize());
        page = performanceAppraisalMapper.getList(page,performanceAppraisalQuery);

        BaseVo<PerformanceAppraisalVo> record = new BaseVo<>();
        record.setRecords(page.getRecords());
        record.setCurrentPage(page.getCurrent());
        record.setPageSize(page.getSize());
        record.setAllRecordNum(page.getTotal());
        return Result.success(record);

    }
    @Override
    public Result addOne(AddPerformanceAppraisalForm performanceAppraisalForm){
        PerformanceAppraisal performanceAppraisal = new PerformanceAppraisal();
        BeanUtil.copyProperties(performanceAppraisalForm,performanceAppraisal);
        performanceAppraisalMapper.insert(performanceAppraisal);
        return Result.success("添加成功");
    }

    @Override
    public Result updateOne(UpdatePerformanceAppraisalForm updatePerformanceAppraisalForm){
        PerformanceAppraisal performanceAppraisal = new PerformanceAppraisal();
        BeanUtil.copyProperties(updatePerformanceAppraisalForm,performanceAppraisal);
        performanceAppraisalMapper.updateById(performanceAppraisal);
        return Result.success("修改成功");
    }
    @Override
    public Result deleteByIds(List<String> list){
        performanceAppraisalMapper.deleteBatchIds(list);
        return Result.success("删除成功");
    }

  @Override
    public List<PerformanceAppraisalExcel> getPerformanceAppraisalExcel(){
       return performanceAppraisalMapper.getExcels();
  }
}




